package net.borderwars.simulator.events;

import net.borderwars.simulator.EventQueue;

import java.util.Date;

/**
 * @author Eric
 *         Date: Feb 2, 2003
 *         Time: 9:57:13 PM
 */
public abstract class BEvent implements Comparable {
// ------------------------------ FIELDS ------------------------------

    static int gid = 0;
    int id = gid++;
    Integer iid = new Integer (id);

    protected Long timeStamp;
    protected EventQueue eq = null;

// --------------------------- CONSTRUCTORS ---------------------------

    public BEvent (Date d) {
        timeStamp = new Long (d.getTime ());
    }

    public BEvent (long l) {
        timeStamp = new Long (l);
    }

// ------------------------ CANONICAL METHODS ------------------------

    public boolean equals (Object obj) {
        if (obj instanceof BEvent) {
            BEvent e = (BEvent) obj;
            if (e.iid.equals (this.iid) && e.timeStamp.equals (this.timeStamp)) {
                return (true);
            }
            else {
                return (false);
            }
        }
        else {
            return (false);
        }
    }

    public int hashCode () {
        return timeStamp.hashCode () + iid.hashCode ();
    }

    public String toString () {
        // DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);
        //DateFormat df = DateFormat.getDateInstance(DateFormat.DEFAULT);
        return (id + ":" + timeStamp.longValue () + ": " + getName ());
        //return (timeStamp.longValue() + "");
    }

    abstract public String getName ();

// ------------------------ INTERFACE METHODS ------------------------

// --------------------- Interface Comparable ---------------------

    public int compareTo (Object o) {
        BEvent event = (BEvent) o;
        return (this.timeStamp.compareTo (event.timeStamp));
    }

// -------------------------- OTHER METHODS --------------------------

    public Long getTimeStamp () {
        return timeStamp;
    }

    abstract public void process ();

    public void setEventQueue (EventQueue eq) {
        this.eq = eq;
    }
}
